package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseUpdEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 系统用户扩展实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserExtDO extends BaseUpdEntity<Long> {

    /** 用户ID，Long */
    @NotNull(message = "用户ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "用户ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long userId;

    /** 登录次数，Long */
    @NotNull(message = "登录次数,不能为空", groups = InsertGroup.class)
    @PositiveOrZero(message = "登录次数,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long loginNum;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return userId;
    }

    @Override
    public void checkBeforeInsert() {
        if (null == userId) {
            throw new VerifyFailException("SysUserExtDO.userId 必须非空");
        }
        if (null == loginNum) {
            throw new VerifyFailException("SysUserExtDO.loginNum 必须非空");
        }
    }

    @Override
    public String toString() {
        return "userId=" + userId +
                ", loginNum=" + loginNum +
                ", " + super.toString();
    }

}
